home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / x / volume10 / contool / part02 < prev    next >
Encoding:
Internet Message Format  |  1990-10-29  |  42.9 KB

  1. Path: uunet!jarthur!usc!cs.utexas.edu!sun-barr!newstop!sun!melmac.harris-atd.com
  2. From: chuck@melmac.harris-atd.com (Chuck Musciano)
  3. Newsgroups: comp.sources.x
  4. Subject: v10i035: contool -- replacement for 'cmdtool -C', Part02/06
  5. Message-ID: <144343@sun.Eng.Sun.COM>
  6. Date: 30 Oct 90 06:25:37 GMT
  7. References: <csx-10i034:contool@uunet.UU.NET>
  8. Sender: news@sun.Eng.Sun.COM
  9. Lines: 1507
  10. Approved: argv@sun.com
  11.  
  12. Submitted-by: chuck@melmac.harris-atd.com (Chuck Musciano)
  13. Posting-number: Volume 10, Issue 35
  14. Archive-name: contool/part02
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then unpack
  18. # it by saving it into a file and typing "sh file".  To overwrite existing
  19. # files, type "sh file -c".  You can also feed this as standard input via
  20. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  21. # will see the following message at the end:
  22. #        "End of archive 2 (of 6)."
  23. # Contents:  contool_ui.h lex.c logging.c misc.c parse.y regexp.c
  24. #   store.c
  25. # Wrapped by chuck@melmac on Fri Aug 17 10:00:51 1990
  26. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  27. if test -f 'contool_ui.h' -a "${1}" != "-c" ; then 
  28.   echo shar: Will not clobber existing file \"'contool_ui.h'\"
  29. else
  30. echo shar: Extracting \"'contool_ui.h'\" \(5115 characters\)
  31. sed "s/^X//" >'contool_ui.h' <<'END_OF_FILE'
  32. X#ifndef    contool_HEADER
  33. X#define    contool_HEADER
  34. X
  35. X/*
  36. X * contool_ui.h - User interface object and function declarations.
  37. X * This file was generated by `gxv' from `contool.G'.
  38. X * DO NOT EDIT BY HAND.
  39. X */
  40. X
  41. Xextern Attr_attribute    INSTANCE;
  42. X
  43. Xextern Xv_opaque    contool_file_menu_create();
  44. Xextern Xv_opaque    contool_view_menu_create();
  45. Xextern Xv_opaque    contool_edit_menu_create();
  46. Xextern Xv_opaque    contool_filter_insert_menu_create();
  47. Xextern Xv_opaque    contool_filter_edit_menu_create();
  48. Xextern Xv_opaque    contool_filter_paste_menu_create();
  49. X
  50. Xtypedef struct {
  51. X    Xv_opaque    base;
  52. X    Xv_opaque    contool_controls;
  53. X    Xv_opaque    file;
  54. X    Xv_opaque    view;
  55. X    Xv_opaque    edit;
  56. X    Xv_opaque    display;
  57. X} contool_base_objects;
  58. X
  59. Xextern contool_base_objects    *contool_base_objects_initialize();
  60. X
  61. Xextern Xv_opaque    contool_base_base_create();
  62. Xextern Xv_opaque    contool_base_contool_controls_create();
  63. Xextern Xv_opaque    contool_base_file_create();
  64. Xextern Xv_opaque    contool_base_view_create();
  65. Xextern Xv_opaque    contool_base_edit_create();
  66. Xextern Xv_opaque    contool_base_display_create();
  67. X
  68. Xtypedef struct {
  69. X    Xv_opaque    props;
  70. X    Xv_opaque    prop_controls;
  71. X    Xv_opaque    default_action;
  72. X    Xv_opaque    default_beep_count;
  73. X    Xv_opaque    default_beep_times;
  74. X    Xv_opaque    default_command;
  75. X    Xv_opaque    log_file;
  76. X    Xv_opaque    log_style;
  77. X    Xv_opaque    print_filter;
  78. X    Xv_opaque    good_icon;
  79. X    Xv_opaque    bad_icon;
  80. X    Xv_opaque    flash_icon;
  81. X    Xv_opaque    stamp_resolution;
  82. X    Xv_opaque    message2;
  83. X    Xv_opaque    max_message;
  84. X    Xv_opaque    message3;
  85. X    Xv_opaque    delete_amount;
  86. X    Xv_opaque    message4;
  87. X    Xv_opaque    props_apply;
  88. X    Xv_opaque    props_reset;
  89. X} contool_props_objects;
  90. X
  91. Xextern contool_props_objects    *contool_props_objects_initialize();
  92. X
  93. Xextern Xv_opaque    contool_props_props_create();
  94. Xextern Xv_opaque    contool_props_prop_controls_create();
  95. Xextern Xv_opaque    contool_props_default_action_create();
  96. Xextern Xv_opaque    contool_props_default_beep_count_create();
  97. Xextern Xv_opaque    contool_props_default_beep_times_create();
  98. Xextern Xv_opaque    contool_props_default_command_create();
  99. Xextern Xv_opaque    contool_props_log_file_create();
  100. Xextern Xv_opaque    contool_props_log_style_create();
  101. Xextern Xv_opaque    contool_props_print_filter_create();
  102. Xextern Xv_opaque    contool_props_good_icon_create();
  103. Xextern Xv_opaque    contool_props_bad_icon_create();
  104. Xextern Xv_opaque    contool_props_flash_icon_create();
  105. Xextern Xv_opaque    contool_props_stamp_resolution_create();
  106. Xextern Xv_opaque    contool_props_message2_create();
  107. Xextern Xv_opaque    contool_props_max_message_create();
  108. Xextern Xv_opaque    contool_props_message3_create();
  109. Xextern Xv_opaque    contool_props_delete_amount_create();
  110. Xextern Xv_opaque    contool_props_message4_create();
  111. Xextern Xv_opaque    contool_props_props_apply_create();
  112. Xextern Xv_opaque    contool_props_props_reset_create();
  113. X
  114. Xtypedef struct {
  115. X    Xv_opaque    filters;
  116. X    Xv_opaque    filter_controls;
  117. X    Xv_opaque    filter_list;
  118. X    Xv_opaque    filter_insert;
  119. X    Xv_opaque    filter_edit;
  120. X    Xv_opaque    filter_update;
  121. X    Xv_opaque    filter_type;
  122. X    Xv_opaque    start;
  123. X    Xv_opaque    stop;
  124. X    Xv_opaque    comment;
  125. X    Xv_opaque    ignore;
  126. X    Xv_opaque    action;
  127. X    Xv_opaque    filter_beep_count;
  128. X    Xv_opaque    filter_beep_times;
  129. X    Xv_opaque    filter_command;
  130. X    Xv_opaque    filters_apply;
  131. X    Xv_opaque    filters_reset;
  132. X} contool_filters_objects;
  133. X
  134. Xextern contool_filters_objects    *contool_filters_objects_initialize();
  135. X
  136. Xextern Xv_opaque    contool_filters_filters_create();
  137. Xextern Xv_opaque    contool_filters_filter_controls_create();
  138. Xextern Xv_opaque    contool_filters_filter_list_create();
  139. Xextern Xv_opaque    contool_filters_filter_insert_create();
  140. Xextern Xv_opaque    contool_filters_filter_edit_create();
  141. Xextern Xv_opaque    contool_filters_filter_update_create();
  142. Xextern Xv_opaque    contool_filters_filter_type_create();
  143. Xextern Xv_opaque    contool_filters_start_create();
  144. Xextern Xv_opaque    contool_filters_stop_create();
  145. Xextern Xv_opaque    contool_filters_comment_create();
  146. Xextern Xv_opaque    contool_filters_ignore_create();
  147. Xextern Xv_opaque    contool_filters_action_create();
  148. Xextern Xv_opaque    contool_filters_filter_beep_count_create();
  149. Xextern Xv_opaque    contool_filters_filter_beep_times_create();
  150. Xextern Xv_opaque    contool_filters_filter_command_create();
  151. Xextern Xv_opaque    contool_filters_filters_apply_create();
  152. Xextern Xv_opaque    contool_filters_filters_reset_create();
  153. X
  154. Xtypedef struct {
  155. X    Xv_opaque    load;
  156. X    Xv_opaque    load_controls;
  157. X    Xv_opaque    load_type;
  158. X    Xv_opaque    load_file;
  159. X    Xv_opaque    accept_load;
  160. X} contool_load_objects;
  161. X
  162. Xextern contool_load_objects    *contool_load_objects_initialize();
  163. X
  164. Xextern Xv_opaque    contool_load_load_create();
  165. Xextern Xv_opaque    contool_load_load_controls_create();
  166. Xextern Xv_opaque    contool_load_load_type_create();
  167. Xextern Xv_opaque    contool_load_load_file_create();
  168. Xextern Xv_opaque    contool_load_accept_load_create();
  169. X
  170. Xtypedef struct {
  171. X    Xv_opaque    store;
  172. X    Xv_opaque    store_controls;
  173. X    Xv_opaque    store_type;
  174. X    Xv_opaque    store_file;
  175. X    Xv_opaque    accept_store;
  176. X} contool_store_objects;
  177. X
  178. Xextern contool_store_objects    *contool_store_objects_initialize();
  179. X
  180. Xextern Xv_opaque    contool_store_store_create();
  181. Xextern Xv_opaque    contool_store_store_controls_create();
  182. Xextern Xv_opaque    contool_store_store_type_create();
  183. Xextern Xv_opaque    contool_store_store_file_create();
  184. Xextern Xv_opaque    contool_store_accept_store_create();
  185. X#endif
  186. END_OF_FILE
  187. if test 5115 -ne `wc -c <'contool_ui.h'`; then
  188.     echo shar: \"'contool_ui.h'\" unpacked with wrong size!
  189. fi
  190. # end of 'contool_ui.h'
  191. fi
  192. if test -f 'lex.c' -a "${1}" != "-c" ; then 
  193.   echo shar: Will not clobber existing file \"'lex.c'\"
  194. else
  195. echo shar: Extracting \"'lex.c'\" \(6635 characters\)
  196. sed "s/^X//" >'lex.c' <<'END_OF_FILE'
  197. X/************************************************************************/
  198. X/*    Copyright 1988-1990 by Chuck Musciano and Harris Corporation    */
  199. X/*                                    */
  200. X/*    Permission to use, copy, modify, and distribute this software    */
  201. X/*    and its documentation for any purpose and without fee is    */
  202. X/*    hereby granted, provided that the above copyright notice    */
  203. X/*    appear in all copies and that both that copyright notice and    */
  204. X/*    this permission notice appear in supporting documentation, and    */
  205. X/*    that the name of Chuck Musciano and Harris Corporation not be    */
  206. X/*    used in advertising or publicity pertaining to distribution    */
  207. X/*    of the software without specific, written prior permission.    */
  208. X/*    Chuck Musciano and Harris Corporation make no representations    */
  209. X/*    about the suitability of this software for any purpose.  It is    */
  210. X/*    provided "as is" without express or implied warranty.  This     */
  211. X/*    software may not be sold without the prior explicit permission    */
  212. X/*    of Harris Corporation.                        */
  213. X/************************************************************************/
  214. X
  215. X#define        RETURN(x)        return(last_token = (x))
  216. X
  217. X#define        FIRST_KEYWORD        BEEP
  218. X#define        LAST_KEYWORD        YES
  219. X#define        NUM_KEYWORDS        (LAST_KEYWORD - FIRST_KEYWORD + 1)
  220. X
  221. XPRIVATE    FILE    *f = NULL;
  222. XPRIVATE    int    last_token = -1;
  223. XPRIVATE    char    buf[1024];
  224. X
  225. XPRIVATE    struct    {char    *name;
  226. X         int    value;
  227. X        } token[] = {{"beep",                 BEEP},
  228. X                 {"check_icon",           CHECK_ICON},
  229. X                 {"command",              COMMAND},
  230. X                 {"comment",              COMMENT},
  231. X                 {"defaults",             DEFAULTS},
  232. X                 {"delete",               DELETE},
  233. X                 {"display",              DISPLAY},
  234. X                 {"filters",              FILTERS},
  235. X                 {"flash",                FLASH},
  236. X                 {"flash_icon",           FLASH_ICON},
  237. X                 {"good_icon",            GOOD_ICON},
  238. X                 {"ignore",               IGNORE},
  239. X                 {"log_before_filtering", LOG_BEFORE_FILTERING},
  240. X                 {"log_file",             LOG_FILE},
  241. X                 {"match",                MATCH},
  242. X                 {"no"     ,              NO},
  243. X                 {"noflash",              NOFLASH},
  244. X                 {"noopen",               NOOPEN},
  245. X                 {"nostamp",              NOSTAMP},
  246. X                 {"open",                 OPEN},
  247. X                 {"print",                PRINT},
  248. X                 {"save",                 SAVE},
  249. X                 {"stamp",                STAMP},
  250. X                 {"timestamp",            TIMESTAMP},
  251. X                 {"to",                   TO},
  252. X                 {"yes",                  YES}};
  253. X
  254. XPRIVATE    struct    {char    first;
  255. X         char    next;
  256. X         int    name;
  257. X        } punc[] = {{'{',  '\0', LBRACE},
  258. X                {'}',  '\0', RBRACE},
  259. X                {'\0', '\0', -1}};
  260. X
  261. X/************************************************************************/
  262. XEXPORT    int    lex_init(path)
  263. X
  264. Xchar    *path;
  265. X
  266. X{
  267. X    if (f)
  268. X       fclose(f);
  269. X    if (f = fopen(path, "r")) {
  270. X       curr_file = strsave(path);
  271. X       line_count = 1;
  272. X       ungetc = -1;
  273. X       parse_errors_occured = 0;
  274. X       return(TRUE);
  275. X       }
  276. X    else
  277. X       return(FALSE);
  278. X}
  279. X
  280. X/************************************************************************/
  281. XPRIVATE    char    getch()
  282. X
  283. X{    register    char    c;
  284. X    static        int    first = TRUE;
  285. X
  286. X    if (ungetc != -1)
  287. X       c = ungetc, ungetc = -1;
  288. X    else {
  289. X       c = getc(f);
  290. X       if (c == '\n')
  291. X          line_count++;
  292. X       }
  293. X    return(c);
  294. X}
  295. X
  296. X/************************************************************************/
  297. XPRIVATE    fix_escapes(buf)
  298. X
  299. Xchar    *buf;
  300. X
  301. X{    char    *q;
  302. X    int    i;
  303. X
  304. X    for (q = buf; *buf; buf++, q++)
  305. X       if (*buf == '\\')
  306. X          *q = *++buf;
  307. X       else
  308. X          *q = *buf;
  309. X    *q = '\0';
  310. X}
  311. X
  312. X/************************************************************************/
  313. XPRIVATE    int    is_keyword(s)
  314. X
  315. Xchar    *s;
  316. X
  317. X{    register    int    cmp, high, low, pos;
  318. X
  319. X    for (low = 0, high = NUM_KEYWORDS - 1; low <= high; )
  320. X       if ((cmp = strcmp(s, token[pos = (high - low) / 2 + low].name)) == 0)
  321. X          return(token[pos].value);
  322. X       else if (cmp < 0)
  323. X          high = pos - 1;
  324. X       else
  325. X          low = pos + 1;
  326. X    return(NULL);
  327. X}
  328. X
  329. X/************************************************************************/
  330. XPRIVATE    int    yylex()
  331. X
  332. X{    register    char    c, c1, *p;
  333. X    register    int    i, j, val;
  334. X    char            *index();
  335. X    double            atof();
  336. X
  337. X    c = getch();
  338. X    while (isspace(c))
  339. X       c = getch();
  340. X    if (isalpha(c)) {
  341. X       p = buf;
  342. X       *p++ = c;
  343. X       while (isalnum(c = getch()) || c == '_')
  344. X          *p++ = c;
  345. X       ungetc = c;
  346. X       *p = '\0';
  347. X       for (p = buf; *p; p++)
  348. X          if (isupper(*p))
  349. X             *p = tolower(*p);
  350. X       if (i = is_keyword(buf))
  351. X          RETURN(i);
  352. X       else {
  353. X          yyerror("unexpected keyword: %s", buf);
  354. X          fclose(f);
  355. X          f = NULL;
  356. X          RETURN(EOF);
  357. X          }
  358. X       }
  359. X    else if (c == '"' || c == '\'') {
  360. X       for (p = buf; TRUE; p++)
  361. X          if ((*p = getch()) == c)
  362. X             break;
  363. X          else if (*p == '\\')
  364. X             *++p = getch();
  365. X          else if (*p == '\n' || *p == '\r') {
  366. X             yyerror("Newline in string not allowed");
  367. X             break;
  368. X             }
  369. X       *p = '\0';
  370. X       fix_escapes(buf);
  371. X       yylval.cpval = strsave(buf);
  372. X       RETURN(STRING);
  373. X       }
  374. X    else if (isdigit(c)) {
  375. X       p = buf;
  376. X       *p++ = c;
  377. X       while (isdigit(c = getch()))
  378. X          *p++ = c;
  379. X       *p = '\0';
  380. X       ungetc = c;
  381. X       yylval.ival = atoi(buf);
  382. X       RETURN(INTEGER);
  383. X       }
  384. X    else if (c == '#') {
  385. X       while ((c = getch()) != '\n' && c != EOF)
  386. X          ;
  387. X       if (c == EOF) {
  388. X          fclose(f);
  389. X          f = NULL;
  390. X          RETURN(EOF);
  391. X          }
  392. X       else
  393. X          RETURN(yylex());
  394. X       }
  395. X    else if (c == EOF) {
  396. X       fclose(f);
  397. X       f = NULL;
  398. X       RETURN(EOF);
  399. X       }
  400. X    else {
  401. X       for (i = 0; punc[i].first; i++)
  402. X          if (c == punc[i].first) {
  403. X             for (c1 = getch(), j = 1; punc[i + j].first == c; j++)
  404. X                if (c1 == punc[i + j].next)
  405. X                   RETURN(punc[i + j].name);
  406. X             ungetc = c1;
  407. X             RETURN(punc[i].name);
  408. X             }
  409. X       yyerror("Invalid character in source file: %c (0x%02x)", c, c);
  410. X       }
  411. X    RETURN(yylex());
  412. X}
  413. X
  414. X/************************************************************************/
  415. XPRIVATE    char    *get_last_token()
  416. X
  417. X{    int    i;
  418. X    static    char    msg[512];
  419. X
  420. X    if (last_token == INTEGER || last_token == STRING)
  421. X       sprintf(msg, "\"%s\"", buf);
  422. X    else if (last_token >= LBRACE && last_token <= RBRACE) {
  423. X       for (i = 0; punc[i].first; i++)
  424. X          if (punc[i].name == last_token) {
  425. X             sprintf(msg, "\"%c\"", punc[i].first);
  426. X             if (punc[i].next)
  427. X                sprintf(msg + 2, "%c\"", punc[i].next);
  428. X             break;
  429. X             }
  430. X       if (punc[i].first == '\0')
  431. X          sprintf(msg, "!!Geez!  Some punctuation, I don't know!!");
  432. X       }
  433. X    else if (last_token >= FIRST_KEYWORD && last_token <= LAST_KEYWORD)
  434. X       sprintf(msg, "\"%s\"", token[last_token - FIRST_KEYWORD].name);
  435. X    else if (last_token == EOF)
  436. X       sprintf(msg, "End Of File");
  437. X    else
  438. X       sprintf(msg, "!!Geez!  Some keyword, I don't know!!");
  439. X    return(msg);
  440. X}
  441. END_OF_FILE
  442. if test 6635 -ne `wc -c <'lex.c'`; then
  443.     echo shar: \"'lex.c'\" unpacked with wrong size!
  444. fi
  445. # end of 'lex.c'
  446. fi
  447. if test -f 'logging.c' -a "${1}" != "-c" ; then 
  448.   echo shar: Will not clobber existing file \"'logging.c'\"
  449. else
  450. echo shar: Extracting \"'logging.c'\" \(4036 characters\)
  451. sed "s/^X//" >'logging.c' <<'END_OF_FILE'
  452. X/************************************************************************/
  453. X/*    Copyright 1988-1990 by Chuck Musciano and Harris Corporation    */
  454. X/*                                    */
  455. X/*    Permission to use, copy, modify, and distribute this software    */
  456. X/*    and its documentation for any purpose and without fee is    */
  457. X/*    hereby granted, provided that the above copyright notice    */
  458. X/*    appear in all copies and that both that copyright notice and    */
  459. X/*    this permission notice appear in supporting documentation, and    */
  460. X/*    that the name of Chuck Musciano and Harris Corporation not be    */
  461. X/*    used in advertising or publicity pertaining to distribution    */
  462. X/*    of the software without specific, written prior permission.    */
  463. X/*    Chuck Musciano and Harris Corporation make no representations    */
  464. X/*    about the suitability of this software for any purpose.  It is    */
  465. X/*    provided "as is" without express or implied warranty.  This     */
  466. X/*    software may not be sold without the prior explicit permission    */
  467. X/*    of Harris Corporation.                        */
  468. X/************************************************************************/
  469. X
  470. X/************************************************************************/
  471. X/*                                    */
  472. X/*    logging.c    message log management                */
  473. X/*                                    */
  474. X/************************************************************************/
  475. X
  476. X#include    <stdio.h>
  477. X#include    <sys/param.h>
  478. X#include    <sys/types.h>
  479. X#include    <xview/xview.h>
  480. X#include    <xview/panel.h>
  481. X#include    <xview/xv_xrect.h>
  482. X
  483. X#include    "manifest.h"
  484. X#include    "contool.h"
  485. X#include    "contool_ui.h"
  486. X
  487. XPUBLIC    Menu_item    start_logging();
  488. XPUBLIC    Menu_item    stop_logging();
  489. X
  490. XPUBLIC    contool_base_objects    *contool_base;
  491. X
  492. XPRIVATE    int    logging = FALSE;
  493. XPRIVATE    FILE    *logfile = NULL;
  494. XPRIVATE    char    *log_path = NULL;
  495. X
  496. X/************************************************************************/
  497. XEXPORT    void    disable_logging()
  498. X
  499. X{
  500. X    if (logging) {
  501. X       fclose(logfile);
  502. X       cond_free(log_path);
  503. X       log_path = NULL;
  504. X       logging = FALSE;
  505. X       }
  506. X    xv_set(contool_base->base, FRAME_RIGHT_FOOTER, "", NULL);
  507. X}
  508. X
  509. X/************************************************************************/
  510. XEXPORT    void    enable_logging()
  511. X
  512. X{    char    buf[1024];
  513. X
  514. X    if (logging) {
  515. X       if (log_path && strcmp(log_path, defaults.log_file) == 0)
  516. X          return;
  517. X       disable_logging();
  518. X       }
  519. X    if (is_empty(defaults.log_file))
  520. X       error("You must specify a log file in the Properties dialog");
  521. X    else if ((logfile = fopen(defaults.log_file, "a")) == NULL)
  522. X       error("Cannot open log file %s : %s", defaults.log_file, sys_errlist[errno]);
  523. X    else {
  524. X       logging = TRUE;
  525. X       log_path = strsave(defaults.log_file);
  526. X       sprintf(buf, "Logging to %s...", defaults.log_file);
  527. X       xv_set(contool_base->base, FRAME_RIGHT_FOOTER, buf, NULL);
  528. X       }
  529. X}
  530. X
  531. X/************************************************************************/
  532. XEXPORT    Menu_item    start_logging(item, op)
  533. X
  534. XMenu_item    item;
  535. XMenu_generate    op;
  536. X
  537. X{    contool_base_objects    *ip = (contool_base_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
  538. X
  539. X    if (op == MENU_DISPLAY)
  540. X       xv_set(item, MENU_INACTIVE, logging, NULL);
  541. X    else if (op == MENU_NOTIFY)
  542. X       enable_logging();
  543. X    return item;
  544. X}
  545. X
  546. X/************************************************************************/
  547. XEXPORT    Menu_item    stop_logging(item, op)
  548. X
  549. XMenu_item    item;
  550. XMenu_generate    op;
  551. X
  552. X{    contool_base_objects    *ip = (contool_base_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
  553. X    
  554. X    if (op == MENU_DISPLAY)
  555. X       xv_set(item, MENU_INACTIVE, !logging, NULL);
  556. X    else if (op == MENU_NOTIFY)
  557. X       disable_logging();
  558. X    return item;
  559. X}
  560. X
  561. X/************************************************************************/
  562. XEXPORT    update_logging()
  563. X
  564. X{
  565. X    if (logging) {
  566. X       disable_logging();
  567. X       enable_logging();
  568. X       }
  569. X}
  570. X
  571. X/************************************************************************/
  572. XEXPORT    write_log(s)
  573. X
  574. Xchar    *s;
  575. X
  576. X{    int    t;
  577. X    static    char    hostname[100] = "";
  578. X
  579. X    if (logging) {
  580. X       if (*hostname == NULL) 
  581. X          if (gethostname(hostname, 99) != 0)
  582. X             strcpy(hostname, "(unknown)");
  583. X       t = time(0);
  584. X       fseek(logfile, 0L, 2);
  585. X       fprintf(logfile, "%s\t%.16s\t%s", hostname, ctime(&t) + 4, s);
  586. X       fflush(logfile);
  587. X       }
  588. X}
  589. END_OF_FILE
  590. if test 4036 -ne `wc -c <'logging.c'`; then
  591.     echo shar: \"'logging.c'\" unpacked with wrong size!
  592. fi
  593. # end of 'logging.c'
  594. fi
  595. if test -f 'misc.c' -a "${1}" != "-c" ; then 
  596.   echo shar: Will not clobber existing file \"'misc.c'\"
  597. else
  598. echo shar: Extracting \"'misc.c'\" \(6150 characters\)
  599. sed "s/^X//" >'misc.c' <<'END_OF_FILE'
  600. X/************************************************************************/
  601. X/*    Copyright 1988-1990 by Chuck Musciano and Harris Corporation    */
  602. X/*                                    */
  603. X/*    Permission to use, copy, modify, and distribute this software    */
  604. X/*    and its documentation for any purpose and without fee is    */
  605. X/*    hereby granted, provided that the above copyright notice    */
  606. X/*    appear in all copies and that both that copyright notice and    */
  607. X/*    this permission notice appear in supporting documentation, and    */
  608. X/*    that the name of Chuck Musciano and Harris Corporation not be    */
  609. X/*    used in advertising or publicity pertaining to distribution    */
  610. X/*    of the software without specific, written prior permission.    */
  611. X/*    Chuck Musciano and Harris Corporation make no representations    */
  612. X/*    about the suitability of this software for any purpose.  It is    */
  613. X/*    provided "as is" without express or implied warranty.  This     */
  614. X/*    software may not be sold without the prior explicit permission    */
  615. X/*    of Harris Corporation.                        */
  616. X/************************************************************************/
  617. X
  618. X#include    <stdio.h>
  619. X#include    <ctype.h>
  620. X#include    <pwd.h>
  621. X
  622. X#include    "manifest.h"
  623. X#include    "contool.h"
  624. X
  625. X/************************************************************************/
  626. XEXPORT    int    getline(stream, string, max)
  627. X
  628. XFILE    *stream;
  629. Xchar    *string;
  630. Xint    max;
  631. X
  632. X{    register    int    i, j;
  633. X
  634. X    i = (int) fgets(string, max, stream);
  635. X    if (i == NULL)
  636. X       return(EOF);
  637. X    j = strlen(string);
  638. X    if (j > 0 && string[j - 1] == '\n')
  639. X       string[--j] = '\0';
  640. X    return(j);
  641. X}
  642. X
  643. X/************************************************************************/
  644. XPRIVATE    delarg(argc, argv)
  645. X
  646. Xint    *argc;
  647. Xchar    **argv;
  648. X
  649. X{    char    *p;
  650. X
  651. X    while (*argv = *(argv+1))
  652. X       argv++;
  653. X    (*argc)--;
  654. X}
  655. X
  656. X/************************************************************************/
  657. XEXPORT    char    getopt(argc, argv, opts, parm)
  658. X
  659. Xint    *argc;
  660. Xchar    **argv;
  661. Xchar    *opts;
  662. Xchar    **parm;
  663. X
  664. X{    char    c, *p, *strcpy(), *index();
  665. X    int    killed;
  666. X
  667. X    *parm = NULL;
  668. X    while (*argv && ((**argv != '-') || (*(*argv+1) == '\0')))
  669. X       argv++;
  670. X    if (*argv == NULL)
  671. X       return(EOF);
  672. X    c = *(*argv+1);
  673. X    *++(*argv) = '-';
  674. X    if (killed = (*(*argv+1) == '\0'))
  675. X       delarg(argc, argv);
  676. X    if ((p = index(opts, c)) == NULL)
  677. X       c = '\0';
  678. X    else if (*(p+1) == ':') {
  679. X       *parm = killed ? *argv : *argv+1;
  680. X       delarg(argc, argv);
  681. X       }
  682. X    return(c);
  683. X}
  684. X
  685. X/************************************************************************/
  686. XEXPORT    int    verify(source, valid)
  687. X
  688. Xchar    *source;
  689. Xchar    *valid;
  690. X
  691. X{    register    char    *s;
  692. X
  693. X    for ( ; *source; source++) {
  694. X       for (s = valid; *s && *s != *source; s++)
  695. X          ;
  696. X       if (*s == '\0')
  697. X          return(0);
  698. X       }
  699. X    return(1);
  700. X}
  701. X
  702. X/************************************************************************/
  703. XEXPORT    char    **saveargs(argc, argv)
  704. X
  705. Xint    argc;
  706. Xchar    **argv;
  707. X
  708. X{    int    i;
  709. X    char    **copy;
  710. X
  711. X    copy = (char **) malloc((argc + 1) * sizeof(char *));
  712. X    for (i = 0; i < argc; i++)
  713. X       strcpy(copy[i] = (char *) malloc(strlen(argv[i]) + 1), argv[i]);
  714. X    copy[i] = (char *) 0;
  715. X    return(copy);
  716. X}
  717. X
  718. X#define        SIZE_INCREMENT        8
  719. X
  720. X/************************************************************************/
  721. XEXPORT    char    **tokenize(line, argc)
  722. X
  723. Xchar    *line;
  724. Xint    *argc;
  725. X
  726. X{    char    match, **argv, *buf, *p;
  727. X    int    limit;
  728. X
  729. X    buf = (char *) malloc(strlen(line) + 1);
  730. X    *argc = 0;
  731. X    argv = (char **) malloc((limit = SIZE_INCREMENT) * sizeof(char *));
  732. X    while (*line) {
  733. X       while (isspace(*line))
  734. X          line++;
  735. X       switch (*line) {
  736. X          case '"'  :
  737. X          case '\'' : match = *line++; /* remove the quote mark */
  738. X                    for (p = buf; *line && (*line != match); ) {
  739. X                       if (*line == '\\')
  740. X                          line++;
  741. X                       if (*line)
  742. X                          *p++ = *line++;
  743. X                       }
  744. X                    if (*line)
  745. X                       line++; /* wipe out quote mark */
  746. X                    break;
  747. X          default   : for (p = buf; *line && !isspace(*line) && (*line != '"') && (*line != '\''); )
  748. X                       *p++ = *line++;
  749. X                    break;
  750. X          }
  751. X       *p = '\0';
  752. X       if (*buf) {
  753. X          argv[(*argc)++] = strsave(buf);
  754. X          if (*argc == limit)
  755. X             argv = (char **) realloc(argv, (limit += SIZE_INCREMENT) * sizeof(char *));
  756. X          }
  757. X       }
  758. X    free(buf);
  759. X    argv[*argc] = (char *) 0;
  760. X    return(argv);
  761. X}
  762. X
  763. X#define        P_POS        5
  764. X#define        L_POS        8
  765. X#define        D_POS        9
  766. X
  767. X#define        PATH        "/dev/ptyp0"
  768. X#define        LETTERS        "pqr"
  769. X#define        DIGITS        "0123456789abcdef"
  770. X
  771. XPRIVATE    char    path[12];
  772. X
  773. X/************************************************************************/
  774. XEXPORT    char    *open_psuedo_tty(master, m_mode, slave, s_mode)
  775. X
  776. XFILE    **master;
  777. Xchar    *m_mode;
  778. XFILE    **slave;
  779. Xchar    *s_mode;
  780. X
  781. X{    char    *s, *t;
  782. X
  783. X    strcpy(path, PATH);
  784. X    for (s = LETTERS; *s && *master == NULL; s++) {
  785. X       path[L_POS] = *s;
  786. X       for (t = DIGITS; *t && *master == NULL; t++) {
  787. X          path[D_POS] = *t;
  788. X          *master = fopen(path, m_mode);
  789. X          }
  790. X       }
  791. X    if (*master != NULL) {
  792. X       path[P_POS] = 't';
  793. X       *slave = fopen(path, s_mode);
  794. X       path[P_POS] = 'p';
  795. X       }
  796. X    return(path);
  797. X}
  798. X
  799. X/************************************************************************/
  800. XEXPORT    char    *expand_tilde(path)
  801. X
  802. Xchar    *path;
  803. X
  804. X{    char    s[1024], *p;
  805. X    struct    passwd    *pw;
  806. X
  807. X    if (*path == '~') {
  808. X       if (path[1] == '/' || path[1] == '\0') {
  809. X          strcpy(s, getenv("HOME"));
  810. X          strcat(s, path + 1);
  811. X          }
  812. X       else {
  813. X          if ((p = index(path, '/')) != NULL)
  814. X             *p = '\0';
  815. X          if ((pw = getpwnam(path + 1)) != NULL) {
  816. X             strcpy(s, pw->pw_dir);
  817. X             if (p != NULL) {
  818. X                strcat(s, "/");
  819. X                strcat(s, p + 1);
  820. X                }
  821. X             }
  822. X          else {
  823. X             if (p != NULL)
  824. X                *p = '/';
  825. X             strcpy(s, path);
  826. X             }
  827. X          }
  828. X       return(strsave(s));
  829. X       }
  830. X    else
  831. X       return(strsave(path));
  832. X}
  833. X
  834. X/************************************************************************/
  835. XEXPORT    int    is_empty(s)
  836. X
  837. Xchar    *s;
  838. X
  839. X{
  840. X    if (s == NULL)
  841. X       return(TRUE);
  842. X    for (; *s; s++)
  843. X       if (!isspace(*s))
  844. X          return(FALSE); 
  845. X    return(TRUE);
  846. X}
  847. X
  848. X/************************************************************************/
  849. XEXPORT    char    *check_escapes(s)
  850. X
  851. Xchar    *s;
  852. X
  853. X{    static    char    buf[1024];
  854. X    char    *p;
  855. X
  856. X    for (p = buf; *s; s++, p++)
  857. X       if (*s == '\\' || *s == '"') {
  858. X          *p++ = '\\';
  859. X          *p = *s;
  860. X          }
  861. X       else
  862. X          *p = *s;
  863. X    *p = '\0';
  864. X    return(buf);
  865. X}
  866. END_OF_FILE
  867. if test 6150 -ne `wc -c <'misc.c'`; then
  868.     echo shar: \"'misc.c'\" unpacked with wrong size!
  869. fi
  870. # end of 'misc.c'
  871. fi
  872. if test -f 'parse.y' -a "${1}" != "-c" ; then 
  873.   echo shar: Will not clobber existing file \"'parse.y'\"
  874. else
  875. echo shar: Extracting \"'parse.y'\" \(6942 characters\)
  876. sed "s/^X//" >'parse.y' <<'END_OF_FILE'
  877. X/************************************************************************/
  878. X/*    Copyright 1988-1990 by Chuck Musciano and Harris Corporation    */
  879. X/*                                    */
  880. X/*    Permission to use, copy, modify, and distribute this software    */
  881. X/*    and its documentation for any purpose and without fee is    */
  882. X/*    hereby granted, provided that the above copyright notice    */
  883. X/*    appear in all copies and that both that copyright notice and    */
  884. X/*    this permission notice appear in supporting documentation, and    */
  885. X/*    that the name of Chuck Musciano and Harris Corporation not be    */
  886. X/*    used in advertising or publicity pertaining to distribution    */
  887. X/*    of the software without specific, written prior permission.    */
  888. X/*    Chuck Musciano and Harris Corporation make no representations    */
  889. X/*    about the suitability of this software for any purpose.  It is    */
  890. X/*    provided "as is" without express or implied warranty.  This     */
  891. X/*    software may not be sold without the prior explicit permission    */
  892. X/*    of Harris Corporation.                        */
  893. X/************************************************************************/
  894. X
  895. X%{
  896. X
  897. X#include    <stdio.h>
  898. X#include    <ctype.h>
  899. X
  900. X#include    "manifest.h"
  901. X#include    "contool.h"
  902. X
  903. XEXPORT    Props    *parsed_defaults;
  904. XEXPORT    Filter    *parsed_filters;
  905. X
  906. XEXPORT    int    parse_errors_occured;
  907. X
  908. XPRIVATE    char    *get_last_token();
  909. X
  910. XPRIVATE    Filter    *curr;
  911. XPRIVATE    char    *curr_file;
  912. XPRIVATE    int    line_count = 1;
  913. XPRIVATE    char    ungetc = -1;
  914. X
  915. X%}
  916. X
  917. X%start    configuration
  918. X
  919. X%union    {char    *cpval;
  920. X     int    ival;
  921. X     Filter    *fval;
  922. X     Props    *pval;
  923. X    }
  924. X
  925. X%token    <cpval>    STRING
  926. X%token    <ival>    INTEGER
  927. X
  928. X%token        LBRACE RBRACE
  929. X
  930. X%token        BEEP CHECK_ICON COMMAND COMMENT DEFAULTS DELETE DISPLAY FILTERS
  931. X        FLASH FLASH_ICON GOOD_ICON IGNORE LOG_BEFORE_FILTERING LOG_FILE
  932. X        MATCH NO NOFLASH NOOPEN NOSTAMP OPEN PRINT SAVE STAMP TIMESTAMP TO YES
  933. X
  934. X%type    <ival>    beep flash old_flash old_open old_stamp open stamp yes_no
  935. X%type    <cpval>    command old_end_string string
  936. X%type    <fval>    filter filter_list old_filter old_filter_list old_ignore old_save
  937. X
  938. X%%
  939. X
  940. Xconfiguration    :    empty
  941. X        |    old_style
  942. X        |    new_style
  943. X        ;
  944. X
  945. Xold_style    :    old_filter_list
  946. X                    { parsed_defaults = NULL;
  947. X                      parsed_filters = $1;
  948. X                    }
  949. X        ;
  950. X
  951. Xold_filter_list    :    old_filter
  952. X                    { $$ = $1; }
  953. X        |    old_filter_list old_filter
  954. X                    { Filter    *f;
  955. X                    
  956. X                      for (f = $1; f->next; f = f->next)
  957. X                         ;
  958. X                      f->next = $2;
  959. X                      $$ = $1;
  960. X                    }
  961. X        ;
  962. X
  963. Xold_filter    :    old_save
  964. X        |    old_ignore
  965. X        ;
  966. X
  967. Xold_save    :    SAVE beep old_flash old_open old_stamp STRING old_end_string
  968. X                    { Filter    *f;
  969. X                      char        *msg;
  970. X
  971. X                      f = (Filter *) malloc(sizeof(Filter));
  972. X                      f->save     = TRUE;
  973. X                      f->beep     = $2;
  974. X                      f->flash    = $3;
  975. X                      f->open     = $4;
  976. X                      f->stamp    = $5;
  977. X                      f->start    = $6;
  978. X                      f->stop     = $7;
  979. X                      f->start_re = NULL;
  980. X                      f->stop_re  = NULL;
  981. X                      f->command  = NULL;
  982. X                      f->comment  = NULL;
  983. X                      f->next     = NULL;
  984. X                      if (msg = compile_exp(f, f->start, f->stop))
  985. X                         yyerror(msg);
  986. X                      $$ = f;
  987. X                    }
  988. X        ;
  989. X
  990. Xold_ignore    :    IGNORE STRING old_end_string
  991. X                    { Filter    *f;
  992. X                      char        *msg;
  993. X                    
  994. X                      f = (Filter *) malloc(sizeof(Filter));
  995. X                      f->save     = FALSE;
  996. X                      f->beep     = 0;
  997. X                      f->flash    = FALSE;
  998. X                      f->open     = FALSE;
  999. X                      f->stamp    = FALSE;
  1000. X                      f->start    = $2;
  1001. X                      f->stop     = $3;
  1002. X                      f->start_re = NULL;
  1003. X                      f->stop_re  = NULL;
  1004. X                      f->command  = NULL;
  1005. X                      f->comment  = NULL;
  1006. X                      f->next     = NULL;
  1007. X                      if (msg = compile_exp(f, f->start, f->stop))
  1008. X                         yyerror(msg);
  1009. X                      $$ = f;
  1010. X                    }
  1011. X        ;
  1012. X
  1013. Xold_flash    :    FLASH
  1014. X                    { $$ = TRUE; }
  1015. X        |    NOFLASH
  1016. X                    { $$ = FALSE; }
  1017. X        ;
  1018. X
  1019. Xold_open    :    OPEN
  1020. X                    { $$ = TRUE; }
  1021. X        |    NOOPEN
  1022. X                    { $$ = FALSE; }
  1023. X        ;
  1024. X
  1025. Xold_stamp    :    STAMP
  1026. X                    { $$ = TRUE; }
  1027. X        |    NOSTAMP
  1028. X                    { $$ = FALSE; }
  1029. X        ;
  1030. X
  1031. Xold_end_string    :    empty
  1032. X                    { $$ = NULL; }
  1033. X        |    TO STRING
  1034. X                    { $$ = $2; }
  1035. X        ;
  1036. X
  1037. Xnew_style    :    defaults
  1038. X        |    filters
  1039. X        |    defaults filters
  1040. X        ;
  1041. X
  1042. Xdefaults    :    DEFAULTS
  1043. X                    { parsed_defaults = (Props *) malloc(sizeof(Props));
  1044. X                      *parsed_defaults = defaults;
  1045. X                    }
  1046. X            LBRACE default_list RBRACE
  1047. X        ;
  1048. X
  1049. Xfilters        :    FILTERS LBRACE filter_list RBRACE
  1050. X                    { parsed_filters = $3; }
  1051. X        ;
  1052. X
  1053. Xdefault_list    :    empty
  1054. X        |    default_list default
  1055. X        ;
  1056. X
  1057. Xdefault        :    beep
  1058. X                    { parsed_defaults->beep = $1; }
  1059. X        |    command
  1060. X                    { parsed_defaults->command = $1; }
  1061. X        |    flash
  1062. X                    { parsed_defaults->flash = $1; }
  1063. X        |    open
  1064. X                    { parsed_defaults->open = $1; }
  1065. X        |    stamp
  1066. X                    { parsed_defaults->stamp = $1; }
  1067. X        |    CHECK_ICON string
  1068. X                    { parsed_defaults->bad_icon = $2; }
  1069. X        |    DELETE INTEGER
  1070. X                    { parsed_defaults->delete_amount = $2; }
  1071. X        |    DISPLAY INTEGER
  1072. X                    { parsed_defaults->max_size = $2; }
  1073. X        |    FLASH_ICON string
  1074. X                    { parsed_defaults->flash_icon = $2; }
  1075. X        |    GOOD_ICON string
  1076. X                    { parsed_defaults->good_icon = $2; }
  1077. X        |    LOG_BEFORE_FILTERING yes_no
  1078. X                    { parsed_defaults->log_after = !$2; }
  1079. X        |    LOG_FILE string
  1080. X                    { parsed_defaults->log_file = $2; }
  1081. X        |    PRINT STRING
  1082. X                    { parsed_defaults->print_filter = $2; }
  1083. X        |    TIMESTAMP INTEGER
  1084. X                    { parsed_defaults->stamp_resolution = $2; }
  1085. X        ;
  1086. X
  1087. Xfilter_list    :    empty
  1088. X                    { $$ = NULL; }
  1089. X        |    filter_list filter
  1090. X                    { Filter    *f;
  1091. X                    
  1092. X                      if ($1 == NULL)
  1093. X                         $$ = $2;
  1094. X                      else {
  1095. X                         for (f = $1; f->next; f = f->next)
  1096. X                            ;
  1097. X                         f->next = $2;
  1098. X                         $$ = $1;
  1099. X                         }
  1100. X                    }
  1101. X        ;
  1102. X
  1103. Xfilter        :    LBRACE
  1104. X                    { curr = (Filter *) malloc(sizeof(Filter));
  1105. X                      bzero(curr, sizeof(Filter));
  1106. X                    }
  1107. X            filter_attr_list RBRACE
  1108. X                    { char    *msg;
  1109. X                    
  1110. X                      if (curr->start == NULL)
  1111. X                         yyerror("no filter pattern specified");
  1112. X                      if (msg = compile_exp(curr, curr->start, curr->stop))
  1113. X                         yyerror(msg);
  1114. X                      $$ = curr;
  1115. X                    }
  1116. X        ;
  1117. X
  1118. Xfilter_attr_list:    empty
  1119. X        |    filter_attr_list filter_attr
  1120. X        ;
  1121. X
  1122. Xfilter_attr    :    beep
  1123. X                    { curr->beep = $1; }
  1124. X        |    command
  1125. X                    { curr->command = $1; }
  1126. X        |    flash
  1127. X                    { curr->flash = $1; }
  1128. X        |    open
  1129. X                    { curr->open = $1; }
  1130. X        |    stamp
  1131. X                    { curr->stamp = $1; }
  1132. X        |    COMMENT string
  1133. X                    { curr->comment = $2; }
  1134. X        |    IGNORE yes_no
  1135. X                    { curr->save = !$2; }
  1136. X        |    MATCH string
  1137. X                    { curr->start = $2; }
  1138. X        |    TO string
  1139. X                    { curr->stop = $2; }
  1140. X        ;
  1141. X
  1142. Xbeep        :    BEEP INTEGER
  1143. X                    { $$ = $2; }
  1144. X        ;
  1145. X
  1146. Xcommand        :    COMMAND string
  1147. X                    { $$ = $2; }
  1148. X        ;
  1149. Xflash        :    FLASH yes_no
  1150. X                    { $$ = $2; }
  1151. X        ;
  1152. X
  1153. Xopen        :    OPEN yes_no
  1154. X                    { $$ = $2; }
  1155. X        ;
  1156. X
  1157. Xstamp        :    STAMP yes_no
  1158. X                    { $$ = $2; }
  1159. X        ;
  1160. X
  1161. Xyes_no        :    YES
  1162. X                    { $$ = TRUE; }
  1163. X        |    NO
  1164. X                    { $$ = FALSE; }
  1165. X        ;
  1166. X
  1167. Xstring        :    STRING
  1168. X                    { $$ = (*$1 == '\0')? NULL : $1; }
  1169. X        ;
  1170. X
  1171. Xempty        : ;
  1172. X
  1173. X%%
  1174. X
  1175. X/************************************************************************/
  1176. XPRIVATE    yyerror(s1, s2, s3, s4, s5, s6, s7)
  1177. X
  1178. Xchar    *s1, *s2, *s3, *s4, *s5, *s6, *s7;
  1179. X
  1180. X{    char    buf1[1024], buf2[1024];
  1181. X
  1182. X    sprintf(buf1, "%s: line %d: ", curr_file, line_count - ((ungetc == '\n')? 1 : 0));
  1183. X    sprintf(buf2, s1, s2, s3, s4, s5, s6, s7);
  1184. X    strcat(buf1, buf2);
  1185. X    if (strcmp(s1, "syntax error") == 0) {
  1186. X       strcat(buf1, " at or near ");
  1187. X       strcat(buf1, get_last_token());
  1188. X       }
  1189. X    error(buf1);
  1190. X    yyclearin;
  1191. X    parse_errors_occured++;
  1192. X}
  1193. X
  1194. X#include "lex.c"
  1195. END_OF_FILE
  1196. if test 6942 -ne `wc -c <'parse.y'`; then
  1197.     echo shar: \"'parse.y'\" unpacked with wrong size!
  1198. fi
  1199. # end of 'parse.y'
  1200. fi
  1201. if test -f 'regexp.c' -a "${1}" != "-c" ; then 
  1202.   echo shar: Will not clobber existing file \"'regexp.c'\"
  1203. else
  1204. echo shar: Extracting \"'regexp.c'\" \(3483 characters\)
  1205. sed "s/^X//" >'regexp.c' <<'END_OF_FILE'
  1206. X/************************************************************************/
  1207. X/*    Copyright 1988-1990 by Chuck Musciano and Harris Corporation    */
  1208. X/*                                    */
  1209. X/*    Permission to use, copy, modify, and distribute this software    */
  1210. X/*    and its documentation for any purpose and without fee is    */
  1211. X/*    hereby granted, provided that the above copyright notice    */
  1212. X/*    appear in all copies and that both that copyright notice and    */
  1213. X/*    this permission notice appear in supporting documentation, and    */
  1214. X/*    that the name of Chuck Musciano and Harris Corporation not be    */
  1215. X/*    used in advertising or publicity pertaining to distribution    */
  1216. X/*    of the software without specific, written prior permission.    */
  1217. X/*    Chuck Musciano and Harris Corporation make no representations    */
  1218. X/*    about the suitability of this software for any purpose.  It is    */
  1219. X/*    provided "as is" without express or implied warranty.  This     */
  1220. X/*    software may not be sold without the prior explicit permission    */
  1221. X/*    of Harris Corporation.                        */
  1222. X/************************************************************************/
  1223. X
  1224. X#include    <stdio.h>
  1225. X
  1226. X#include    "manifest.h"
  1227. X#include    "contool.h"
  1228. X
  1229. XPRIVATE    regexp_error();
  1230. X
  1231. X#define        INIT            register char *expbuf = ep, *sp = instring;
  1232. X#define        GETC()            (*sp++)
  1233. X#define        PEEKC()            (*sp)
  1234. X#define        UNGETC(c)        (--sp)
  1235. X#define        RETURN(p)        {bcopy(expbuf, sp = (char *) malloc(p - expbuf), p - expbuf); return(sp);}
  1236. X#define        ERROR(val)        {regexp_error(val, instring); return(NULL);}
  1237. X
  1238. X#include    <regexp.h>
  1239. X
  1240. XPRIVATE    char    error_message[512];
  1241. X
  1242. X/************************************************************************/
  1243. XEXPORT    int    match_exp(exp, circ, str)
  1244. X
  1245. Xchar    *exp;
  1246. Xint    circ;
  1247. Xchar    *str;
  1248. X
  1249. X{    char    *p;
  1250. X    int    result;
  1251. X
  1252. X    p = str + strlen(str) - 1;
  1253. X    if (p >= str && *p == '\n')
  1254. X       *p = '\0';
  1255. X    circf = circ;
  1256. X    result = step(str, exp);
  1257. X    if (p >= str && *p == '\0')
  1258. X       *p = '\n';
  1259. X    return(result);
  1260. X}
  1261. X
  1262. X/************************************************************************/
  1263. XPRIVATE    regexp_error(val, string)
  1264. X
  1265. Xint    val;
  1266. Xchar    *string;
  1267. X
  1268. X{    char    *msg;
  1269. X
  1270. X    switch (val) {
  1271. X       case 11 : msg = "range endpoint too large";
  1272. X       case 16 : msg = "bad number";
  1273. X       case 25 : msg = "\"\\digit\" out of range";
  1274. X       case 36 : msg = "illegal or missing delimiter";
  1275. X       case 41 : msg = "no remembered search string";
  1276. X       case 42 : msg = "\\(\\) imbalance";
  1277. X       case 43 : msg = "too many \\(";
  1278. X       case 44 : msg = "more than 2 numbers given in \\{\\}";
  1279. X       case 45 : msg = "} expected after \\";
  1280. X       case 46 : msg = "first number exceeds second in \\{\\}";
  1281. X       case 49 : msg = "[] imbalance";
  1282. X       case 50 : msg = "regular expression overflow";
  1283. X       default : msg = "regular expression error";
  1284. X       }
  1285. X    sprintf(error_message, "%s in %s", msg, string);
  1286. X}
  1287. X
  1288. X/************************************************************************/
  1289. XEXPORT    char    *compile_exp(filter, start, stop)
  1290. X
  1291. XFilter    *filter;
  1292. Xchar    *start;
  1293. Xchar    *stop;
  1294. X
  1295. X{    char    rbuf[1024], *sre, *ere;
  1296. X    int    sc, ec;
  1297. X
  1298. X    sre = ere = NULL;
  1299. X    if (start) {
  1300. X       if ((sre = compile(start, rbuf, rbuf+1024, '\0')) == NULL)
  1301. X          return(error_message);
  1302. X       sc = circf;
  1303. X       }
  1304. X    if (stop) {
  1305. X       if ((ere = compile(stop, rbuf, rbuf+1024, '\0')) == NULL) {
  1306. X          cond_free(sre);
  1307. X          return(error_message);
  1308. X          }
  1309. X       ec = circf;
  1310. X       }
  1311. X    if (filter) {
  1312. X       filter->start = start;
  1313. X       filter->stop = stop;
  1314. X       filter->start_re = sre;
  1315. X       filter->stop_re = ere;
  1316. X       filter->start_circf = sc;
  1317. X       filter->stop_circf = ec;
  1318. X       }
  1319. X    else {
  1320. X       cond_free(sre);
  1321. X       if (ere)
  1322. X          cond_free(ere);
  1323. X       }
  1324. X    return(NULL);
  1325. X}
  1326. END_OF_FILE
  1327. if test 3483 -ne `wc -c <'regexp.c'`; then
  1328.     echo shar: \"'regexp.c'\" unpacked with wrong size!
  1329. fi
  1330. # end of 'regexp.c'
  1331. fi
  1332. if test -f 'store.c' -a "${1}" != "-c" ; then 
  1333.   echo shar: Will not clobber existing file \"'store.c'\"
  1334. else
  1335. echo shar: Extracting \"'store.c'\" \(5792 characters\)
  1336. sed "s/^X//" >'store.c' <<'END_OF_FILE'
  1337. X/************************************************************************/
  1338. X/*    Copyright 1988-1990 by Chuck Musciano and Harris Corporation    */
  1339. X/*                                    */
  1340. X/*    Permission to use, copy, modify, and distribute this software    */
  1341. X/*    and its documentation for any purpose and without fee is    */
  1342. X/*    hereby granted, provided that the above copyright notice    */
  1343. X/*    appear in all copies and that both that copyright notice and    */
  1344. X/*    this permission notice appear in supporting documentation, and    */
  1345. X/*    that the name of Chuck Musciano and Harris Corporation not be    */
  1346. X/*    used in advertising or publicity pertaining to distribution    */
  1347. X/*    of the software without specific, written prior permission.    */
  1348. X/*    Chuck Musciano and Harris Corporation make no representations    */
  1349. X/*    about the suitability of this software for any purpose.  It is    */
  1350. X/*    provided "as is" without express or implied warranty.  This     */
  1351. X/*    software may not be sold without the prior explicit permission    */
  1352. X/*    of Harris Corporation.                        */
  1353. X/************************************************************************/
  1354. X
  1355. X/************************************************************************/
  1356. X/*                                    */
  1357. X/*    store.c        contool store dialog manager            */
  1358. X/*                                    */
  1359. X/************************************************************************/
  1360. X
  1361. X#include    <stdio.h>
  1362. X#include    <ctype.h>
  1363. X#include    <sys/param.h>
  1364. X#include    <sys/types.h>
  1365. X#include    <sys/file.h>
  1366. X#include    <xview/xview.h>
  1367. X#include    <xview/panel.h>
  1368. X#include    <xview/notice.h>
  1369. X#include    <xview/xv_xrect.h>
  1370. X
  1371. X#include    "manifest.h"
  1372. X#include    "contool.h"
  1373. X#include    "contool_ui.h"
  1374. X
  1375. X#define        yes_no(x)        ((x)? "yes" : "no")
  1376. X
  1377. XPUBLIC    contool_base_objects    *contool_base;
  1378. X
  1379. XPRIVATE    contool_store_objects    *contool_store = NULL;
  1380. X
  1381. X/************************************************************************/
  1382. XEXPORT    Menu_item    popup_save_config(item, op)
  1383. X
  1384. XMenu_item    item;
  1385. XMenu_generate    op;
  1386. X
  1387. X{    contool_base_objects * ip = (contool_base_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
  1388. X
  1389. X    if (op == MENU_NOTIFY) {
  1390. X       if (contool_store == NULL) {
  1391. X          contool_store = contool_store_objects_initialize(NULL, ip->base);
  1392. X          xv_set(contool_store->store_file,
  1393. X                      PANEL_NOTIFY_LEVEL, PANEL_SPECIFIED,
  1394. X                      PANEL_NOTIFY_STRING, "\n\r ",
  1395. X                   NULL);
  1396. X          xv_set(contool_store->store_type, PANEL_VALUE, 3, NULL);
  1397. X          place_dialog(ip->base, contool_store->store);
  1398. X          }
  1399. X       xv_set(contool_store->store_file, PANEL_VALUE, filter_file, NULL);
  1400. X       xv_set(contool_store->store, XV_SHOW, TRUE, NULL);
  1401. X       }
  1402. X    return item;
  1403. X}
  1404. X
  1405. X/************************************************************************/
  1406. XEXPORT    void    store_filters(item, event)
  1407. X
  1408. XPanel_item    item;
  1409. XEvent        *event;
  1410. X
  1411. X{    contool_store_objects    *ip = (contool_store_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
  1412. X    char    *path, buf[1024];
  1413. X    FILE    *f;
  1414. X    int    kind;
  1415. X    Filter    *filt;
  1416. X
  1417. X    path = expand_tilde(xv_get(ip->store_file, PANEL_VALUE));
  1418. X    if (access(path, W_OK) == 0) {
  1419. X       sprintf(buf, "File \"%s\" exists.  You can:", path);
  1420. X       kind = notice_prompt(contool_base->base, NULL,
  1421. X                      NOTICE_MESSAGE_STRINGS, buf, NULL,
  1422. X                      NOTICE_BUTTON_YES, "Overwrite",
  1423. X                      NOTICE_BUTTON_NO, "Cancel",
  1424. X                   NULL);
  1425. X       if (kind == 0) {
  1426. X          xv_set(item, PANEL_NOTIFY_STATUS, XV_ERROR, NULL);
  1427. X          free(path);
  1428. X          return;
  1429. X          }
  1430. X       }
  1431. X    if ((f = fopen(path, "w")) == NULL) {
  1432. X       error("Cannot write to %s: %s", path, sys_errlist[errno]);
  1433. X       xv_set(item, PANEL_NOTIFY_STATUS, XV_ERROR, NULL);
  1434. X       free(path);
  1435. X       }
  1436. X    else {
  1437. X       kind = (int) xv_get(ip->store_type, PANEL_VALUE);
  1438. X       if (kind & 1) {
  1439. X          fprintf(f, "defaults {\n");
  1440. X          fprintf(f, "   beep                 %d\n", defaults.beep);
  1441. X          fprintf(f, "   command              \"%s\"\n", check_escapes(is_null(defaults.command)));
  1442. X          fprintf(f, "   flash                %s\n", yes_no(defaults.flash));
  1443. X          fprintf(f, "   open                 %s\n", yes_no(defaults.open));
  1444. X          fprintf(f, "   stamp                %s\n", yes_no(defaults.stamp));
  1445. X          fprintf(f, "   good_icon            \"%s\"\n", is_null(defaults.good_icon));
  1446. X          fprintf(f, "   check_icon           \"%s\"\n", is_null(defaults.bad_icon));
  1447. X          fprintf(f, "   flash_icon           \"%s\"\n", is_null(defaults.flash_icon));
  1448. X          fprintf(f, "   print                \"%s\"\n", defaults.print_filter);
  1449. X          fprintf(f, "   log_file             \"%s\"\n", is_null(defaults.log_file));
  1450. X          fprintf(f, "   log_before_filtering %s\n", yes_no(!defaults.log_after));
  1451. X          fprintf(f, "   timestamp            %d\n", defaults.stamp_resolution);
  1452. X          fprintf(f, "   display              %d\n", defaults.max_size);
  1453. X          fprintf(f, "   delete               %d\n", defaults.delete_amount);
  1454. X          fprintf(f, "}\n");
  1455. X          }
  1456. X       if (kind & 2) {
  1457. X          fprintf(f, "filters {\n");
  1458. X          for (filt = filters; filt; filt = filt->next) {
  1459. X             fprintf(f, "   {\n");
  1460. X             fprintf(f, "      match   \"%s\"\n", check_escapes(filt->start));
  1461. X             if (filt->stop)
  1462. X                fprintf(f, "      to      \"%s\"\n", check_escapes(filt->stop));
  1463. X             if (filt->comment)
  1464. X                fprintf(f, "      comment \"%s\"\n", check_escapes(filt->comment));
  1465. X             if (filt->save) {
  1466. X                fprintf(f, "      ignore  no\n");
  1467. X                fprintf(f, "      beep    %d\n", filt->beep);
  1468. X                fprintf(f, "      command \"%s\"\n", check_escapes(is_null(filt->command)));
  1469. X                fprintf(f, "      flash   %s\n", yes_no(filt->flash));
  1470. X                fprintf(f, "      open    %s\n", yes_no(filt->open));
  1471. X                fprintf(f, "      stamp   %s\n", yes_no(filt->stamp));
  1472. X                }
  1473. X             else
  1474. X                fprintf(f, "      ignore  yes\n");
  1475. X             fprintf(f, "   }\n");
  1476. X             }
  1477. X          fprintf(f, "}\n");
  1478. X          }
  1479. X       fclose(f);
  1480. X       filter_file = path;
  1481. X       }
  1482. X}
  1483. END_OF_FILE
  1484. if test 5792 -ne `wc -c <'store.c'`; then
  1485.     echo shar: \"'store.c'\" unpacked with wrong size!
  1486. fi
  1487. # end of 'store.c'
  1488. fi
  1489. echo shar: End of archive 2 \(of 6\).
  1490. cp /dev/null ark2isdone
  1491. MISSING=""
  1492. for I in 1 2 3 4 5 6 ; do
  1493.     if test ! -f ark${I}isdone ; then
  1494.     MISSING="${MISSING} ${I}"
  1495.     fi
  1496. done
  1497. if test "${MISSING}" = "" ; then
  1498.     echo You have unpacked all 6 archives.
  1499.     rm -f ark[1-9]isdone
  1500. else
  1501.     echo You still need to unpack the following archives:
  1502.     echo "        " ${MISSING}
  1503. fi
  1504. ##  End of shell archive.
  1505. exit 0
  1506.  
  1507. Chuck Musciano                ARPA  : chuck@trantor.harris-atd.com
  1508. Harris Corporation             Usenet: ...!uunet!x102a!trantor!chuck
  1509. PO Box 37, MS 3A/1912            AT&T  : (407) 727-6131
  1510. Melbourne, FL 32902            FAX   : (407) 729-2537
  1511.  
  1512. A good newspaper is never good enough,
  1513.     but a lousy newspaper is a joy forever.        -- Garrison Keillor
  1514.  
  1515. dan
  1516. ----------------------------------------------------
  1517. O'Reilly && Associates   argv@sun.com / argv@ora.com
  1518. Opinions expressed reflect those of the author only.
  1519.